package com.xy.smartsms.helper;

import android.content.Context;
import android.os.Handler;
import android.os.Message;

import com.xy.smartsms.data.SmsItem;
import com.xy.smartsms.vista.BubbleViewHolder;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by admin on 2017/8/28 0028.
 */

public class SmartSmsCardHelper {
    private BubbleViewHolder mBubbleViewHolder = null;

    public SmartSmsCardHelper(Context context, final SmartSmsCardOptions options) {
        mBubbleViewHolder = new BubbleViewHolder(context, new Handler() {
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case BubbleViewHolder.MESSAGE_SHOW_DEFAULT:
                        options.getCallback().showDefaultItem((Boolean) msg.obj);
                        break;

                    case BubbleViewHolder.MESSAGE_COMPLETE_ITEM:
                        options.getHandler().obtainMessage(msg.what, msg.obj).sendToTarget();
                        break;

                    default:
                        break;
                }
            }
        }, options.getRootView(), options.getParentView());

        Map<String, String> map = new HashMap<>();
        map.put(BubbleViewHolder.ID_SIMPLE, String.valueOf(options.getSimpleBubbleId()));
        map.put(BubbleViewHolder.ID_RICH, String.valueOf(options.getRichBubbleId()));
        map.put(BubbleViewHolder.ID_CONTENT, String.valueOf(options.getContentId()));
        mBubbleViewHolder.setMap(map);
    }

    public void bind(SmsItem item) {
        mBubbleViewHolder.bind(item);
    }

}
